var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
let session = require("express-session")

var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');

var app = express();

app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

// ejs设置默认引擎
app.set("view engine","ejs");

// session的配置
let options = {
    secret:"密钥字符串随便写",
    resave:false,
    saveUninitialized:true
}
app.use( session(options) )




app.use('/', indexRouter);
app.use('/users', usersRouter);

app.use((err,req,res,next)=>{
    res.render("./error.ejs",{err});
});

module.exports = app;
